package com.putong35.easyui.ric;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.putong35.common.baseactfrag.activity.BaseActivity;
import com.putong35.common.utils.EasyToast;
import com.putong35.easyui.R;

import java.util.List;


/**
 * 发布图文
 *
 * @Author: Administrator
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2017/4/11
 * @Version: 1.0.0
 */
public class ReleaseImageContentActivity extends BaseActivity {

    EditText etTitle;
    EditText etContent;

    public static void start(Context context, String type, String channelId) {
        Intent starter = new Intent(context, ReleaseImageContentActivity.class);
        starter.putExtra("type", type);
        starter.putExtra("channelId", channelId);
        context.startActivity(starter);
    }

    public static void start(Context context, String type, String channelId, String clubId) {
        Intent starter = new Intent(context, ReleaseImageContentActivity.class);
        starter.putExtra("type", type);
        starter.putExtra("channelId", channelId);
        starter.putExtra("clubId", clubId);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("发布图文");
        enableBackButton();
        getCustomToolbar().addRightButton("发布", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkAndReqRelease();
            }
        });

        etTitle = (EditText) findViewById(R.id.etTitle);
        etContent = (EditText) findViewById(R.id.etContent);

    }

    private void checkAndReqRelease() {
        // check
        String title = etTitle.getText().toString().trim();
        if (title.length() <= 0) {
            EasyToast.showToast(this, "请输入标题");
            return;
        }

        String content = etContent.getText().toString().trim();
        if (content.length() <= 0) {
            EasyToast.showToast(this, "请输入内容");
            return;
        }

        PickPictureFragment fragment = (PickPictureFragment) getSupportFragmentManager().findFragmentById(R.id.fragPickPicture);
        reqRelease(title, content , fragment.getSelectedPictureUrls());

    }

    private void reqRelease(String title, String content, List<String> imgList) {
        EasyToast.showToast(this, "发布 img list size = " + imgList.size());
    }


    @Override
    public View createDataView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        return layoutInflater.inflate(R.layout.ric_activity_release_image_content, viewGroup, false);
    }

}